﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WordNet.Core;
using WordNet.Core.ElementContracts;
using WordNet.Core.DataContract;
using Moq;

namespace UnitTestDataProvider.TestClasses
{
    public abstract class TestParserBase
    {
        protected bool _parserCalled;
        protected bool _lineNotEmpty;

        public bool Verify()
        {
            return _parserCalled && _lineNotEmpty;
        }

        public void Reset()
        {
            _lineNotEmpty = false;
            _parserCalled = false;
        }
    }
    
    [Export(typeof(IParser<ISynset>))]
    [PartCreationPolicy(CreationPolicy.Shared)]
    public class DataLineParserTest: TestParserBase, IParser<ISynset>
    {
        public ISynset Parse(string line)
        {
            base._parserCalled = true;
            base._lineNotEmpty = !String.IsNullOrEmpty(line);
            Mock<ISynset> mock = new Mock<ISynset>();
            mock.Setup(s => s.Gloss).Returns(line);
            return mock.Object;
        }
    }

    [Export(typeof(IParser<IExceptionEntryProxy>))]
    [PartCreationPolicy(CreationPolicy.Shared)]
    public class ExceptionLineParser: TestParserBase, IParser<IExceptionEntryProxy>
    {
        public IExceptionEntryProxy Parse(string line)
        {
            base._parserCalled = true;
            base._lineNotEmpty = String.IsNullOrEmpty(line);
            Mock<IExceptionEntryProxy> mock = new Mock<IExceptionEntryProxy>();
            mock.Setup(m => m.SurfaceForm).Returns(line);
            return mock.Object;
        }
    }

    [Export(typeof(IParser<IIndexWord>))]
    [PartCreationPolicy(CreationPolicy.Shared)]
    public class IndexLineParser: TestParserBase, IParser<IIndexWord>
    {
        public IIndexWord Parse(string line)
        {
            base._parserCalled = true;
            base._lineNotEmpty = !String.IsNullOrEmpty(line);
            Mock<IIndexWord> mock = new Mock<IIndexWord>();
            mock.Setup(m => m.Lemma).Returns(line);
            return mock.Object;
            
        }
    }

    [Export(typeof(IParser<ISenseEntry>))]
    [PartCreationPolicy(CreationPolicy.Shared)]
    public class SenseLineParser: TestParserBase, IParser<ISenseEntry>
    {
        public ISenseEntry Parse(string line)
        {
            base._parserCalled = true;
            base._lineNotEmpty = !String.IsNullOrEmpty(line);
            Mock<ISenseEntry> mock = new Mock<ISenseEntry>();
            mock.Setup(m => m.Offset).Returns(int.Parse(line));
            return mock.Object;
       }
    }
}
